﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GameEngineer.BaseShape;
using GameEngineer.BaseMatrix;
using System.Timers;

namespace GameEngineer
{
    public partial class Form1 : Form
    {
        //创建三角形对象
        private BaseShape.BaseShape mShape;  
        //计数器
        private float mTimer = 0f;

        public Form1()
        {
            InitializeComponent();
        }

        //画出图形形状
        private void UpdatePaint(object sender,PaintEventArgs args)
        {
            //将窗口原点坐标设置到中心点
            args.Graphics.TranslateTransform(this.Size.Width / 2, this.Size.Height / 2);

            mShape.Draw(args.Graphics);
        }

        private void Form1_Load_1(object sender, EventArgs e)
        {
            float triangleWidth = 100f;

            mShape = new TriangleShape
                    (
                        new Vertex.Vertex4(0, -triangleWidth, 0, 1),
                        new Vertex.Vertex4(triangleWidth, triangleWidth, 0, 1),
                        new Vertex.Vertex4(-triangleWidth, triangleWidth, 0, 1)
                    );
            this.Paint += new PaintEventHandler(UpdatePaint);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Matrix4X4 scaleMatrix = new ScaleMatrix4X4(1f, 1f, 1f, 1);
            Matrix4X4 rotateMatrix = new RotateMatrix4X4(mTimer+=0.1f);
            Matrix4X4 viewMatrix = new ViewMatrix4X4();
            Matrix4X4 projectionMatrix = new ProjectionMatrix4X4();

            Matrix4X4 m = rotateMatrix.Mul(scaleMatrix);
            Matrix4X4 mv = m.Mul(viewMatrix);
            Matrix4X4 mvp = mv.Mul(projectionMatrix);

            mShape.Transform(mvp);

            this.Invalidate();
        }
    }
}
